package com.kjsb.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.kjsb.dao.ProjectCategoryMapper;
import com.kjsb.dao.ProjectManageDao;
import com.kjsb.entity.ProjectCategory;
import com.kjsb.service.ProjectCategoryService;
import com.kjsb.vo.ProjectSearch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class ProjectCategoryServiceImpl implements ProjectCategoryService {

    @Autowired
    private ProjectCategoryMapper progectCategoryMapper;

    /**
     * 查询全部项目类并返回
     *
     * @return
     */
    @Override
    public List<ProjectCategory> getAll() {
        List<ProjectCategory> projectCategories = progectCategoryMapper.selectList(null);
        return projectCategories;
    }

    /**
     * 通过项目类id查询项目类并返回
     *
     * @return
     */
    @Override
    public ProjectCategory getOneById(int categoryid) {
        return progectCategoryMapper.selectById(categoryid);
    }

    /**
     * 通过项目类id查询全部项目id并返回
     *
     * @return
     */
    @Override
    public List<Integer> getAllProjectByCategoryId(int categoryId) {
        return progectCategoryMapper.selectProjectByCategoryid(categoryId);
    }

    /**
     * 通过项目类id查询全部unit id并返回
     * @param categoryId
     * @return
     */
    public List<Integer> getAllUnitByCategoryId(int categoryId){
        return progectCategoryMapper.selectAllUnitByCategoryId(categoryId);
    }
    /**
     * 添加一个项目类
     *
     * @return
     */
    @Override
    public Boolean save(ProjectCategory projectCategory) {
        return progectCategoryMapper.insert(projectCategory) > 0;
    }

    /**
     * 修改一个项目类的名称
     *
     * @return
     */
    @Override
    public Boolean updateCategoryName(ProjectCategory projectCategory) {
        int flag = progectCategoryMapper.updateById(projectCategory);
        return flag > 0;
    }


    /**
     * 通过项目类id删除一个项目类
     *
     * @return
     */
    @Override
    public Boolean removeById(int categoryid) {
        return progectCategoryMapper.deleteBycategoryid(categoryid) > 0;
    }
    /**
     * 通过项目类id删除属于该项目类的所有项目
     *
     * @return
     */
    @Override
    public Boolean removeAllProjectByCategoryId(int categoryId) {
        return progectCategoryMapper.deleteProjectByCategoryid(categoryId) > 0;
    }

    /**
     * 通过项目类id删除属于该项目类的所有unit
     * @param categoryId
     * @return
     */
    @Override
    public Boolean removeAllUnitByCategoryId(int categoryId) {
        return progectCategoryMapper.deleteProjectByCategoryid(categoryId)> 0;
    }

    @Override
    public List<ProjectCategory> getExpertProject(Integer expertid) {
        return progectCategoryMapper.getExpertProject(expertid);
    }

    @Override
    public List<ProjectCategory> getByEid(int eid) {
        Map<String,Object> map =new HashMap<>();
        map.put("expertid",eid);
        return progectCategoryMapper.selectByMap(map);
    }
}
